package com.feiyu.controller;


import com.feiyu.pojo.Dept;
import com.feiyu.service.DeptService;
import com.feiyu.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Insert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j    //日志
@RestController
  //@RequestMapping("/depts")        可以抽取公共路径
public class DeptController {

    @Autowired
    private DeptService deptService;

    /**
     * 查询部门数据
     * @return
     */
    //@RequestMapping(value = "/depts",method = RequestMethod.GET )
    @GetMapping("/depts")
    public Result list(){
         log.info("查询全部部门");

        List<Dept> deptList =deptService.list();


        return  Result.success(deptList);
    }

    /**
     * 删除部门
     * @param id
     * @return
     */

    @DeleteMapping("/depts/{id}")
    public  Result delete( @PathVariable Integer id){
        deptService.delete(id);

        log.info("按照id删除部门"+":id");
        return  Result.success();
    }


    /**
     * 新增部门
     * @param dept
     * @return
     */
    @PostMapping("/depts")
    public  Result   add(@RequestBody Dept dept){

        deptService.add(dept);

        log.info("添加部门");
        return  Result.success();

    }

@GetMapping("/depts/{id}")
    public  Result  list02(@PathVariable Integer id){

       Dept dept = deptService.list02(id);

        log.info("根据id查询部门");
        return  Result.success(dept);
    }

    /**
     * 更新部门
     * @param dept
     * @return
     */
    @PutMapping("depts")
    public  Result update(@RequestBody Dept dept){

        deptService.update(dept);

        log.info("更新部门"+"dept");
        return  Result.success();
    }


}
